package com.sskj.mine.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.asset.data.ExchangeConfigBean;
import com.sskj.mine.bean.ExchangeCoinBean;
import com.sskj.mine.bean.ExchangeUsable;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.ExchangeActivity;

import java.util.List;


/**
 * @author Hey
 * Create at  2019/05/04
 */
public class ExchangePresenter extends BasePresenter<ExchangeActivity> {


    /**
     * 兑换页面
     *
     * @param type 1代币兑usdt 2 usdt兑换代币
     * @return
     */
    public void getExchangeWallet(String type) {
        httpService.getExchangeWallet(type).execute(new JsonCallBack<HttpData<ExchangeConfigBean>>() {
            @Override
            public void onSuccess(Response<HttpData<ExchangeConfigBean>> response) {
                HttpData<ExchangeConfigBean> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {

                    mView.updateWallet(httpData.getData());
                }
            }
        });
    }

    public void getExchangeCoin(int formWalletType, int toWalletType) {
        httpService.getExchangeCoin(formWalletType, toWalletType)
                .execute(new JsonCallBack<HttpData<List<ExchangeCoinBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<ExchangeCoinBean>>> response) {
                        HttpData<List<ExchangeCoinBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.updateCoin(httpData.getData());
                        }
                    }
                });
    }

    public void getUsable(String formWalletType, String id) {
        httpService.getExchangeUsable(formWalletType, id)
                .execute(new JsonCallBack<HttpData<ExchangeUsable>>() {
                    @Override
                    public void onSuccess(Response<HttpData<ExchangeUsable>> response) {
                        HttpData<ExchangeUsable> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.updateUsable(httpData.getData().getUsable());
                        }
                    }
                });
    }


    public void exchange(String formWalletType, String toWalletType, String rotationNum, String payment_password, String id) {
        httpService.exchange(formWalletType, toWalletType, rotationNum, payment_password, id)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.exchangeSuccess();
                        }
                    }
                });
    }


}
